Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-fields

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-fields

Turns GraphQLResolveInfo into a map of the requested fields

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
173K
decreased by-15.39%
Maintainers
1
Weekly downloads
 
Created

What is graphql-fields?

The graphql-fields npm package is a utility for extracting the fields requested in a GraphQL query. It helps in resolving only the necessary fields, optimizing the performance of your GraphQL server by avoiding over-fetching data.

What are graphql-fields's main functionalities?

Extracting Fields from a GraphQL Query

This feature allows you to extract the fields requested in a GraphQL query. By using the `graphqlFields` function and passing the `info` object from the resolver, you can get an object representing the fields requested. This can be used to optimize data fetching by only querying the necessary fields from your data source.

const graphqlFields = require('graphql-fields');

const resolvers = {
  Query: {
    user: (parent, args, context, info) => {
      const fields = graphqlFields(info);
      console.log(fields); // Logs the fields requested in the query
      // Fetch and return the user data based on the requested fields
    }
  }
};

Handling Nested Fields

This feature allows you to handle nested fields in a GraphQL query. The `graphqlFields` function will return an object that includes nested fields, enabling you to understand the full structure of the query and fetch data accordingly.

const graphqlFields = require('graphql-fields');

const resolvers = {
  Query: {
    user: (parent, args, context, info) => {
      const fields = graphqlFields(info);
      console.log(fields); // Logs nested fields as well
      // Fetch and return the user data based on the requested fields
    }
  }
};

Other packages similar to graphql-fields

Keywords

FAQs

Package last updated on 05 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc